package Funcionalidades.ABMCompetencia;

import Funcionalidades.Menues.FrameUsuarioAutenticado;
import Funcionalidades.Menues.iDialogGeneral;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.DefaultComboBoxModel;

public class iModalidadEliminatoria extends iDialogGeneral  {

	private static final long serialVersionUID = 1L;
	private final JPanel contentPanel = new JPanel();
	private JTextField txtFaltaRival;
	private JSpinner spCantidadSets;
	private JComboBox<String> cbForma;
	private JButton okButton;
	private JButton cancelButton;

	
	private String forma;
	private int sets;
	private int rival;
	
	
	public iModalidadEliminatoria(FrameUsuarioAutenticado perteneciente, boolean modal) {
		super(perteneciente,modal);
		setBoton(false);
		label= new Dimension(200, 30);
		
		Dimension tam= new Dimension(400, 280);
		setTamanio(tam);
		
		setObligatorios(new Vector<Object>());

		
		getContentPane().setLayout(new BorderLayout());
		{
			JPanel panelTitulo = new JPanel();
			getContentPane().add(panelTitulo, BorderLayout.NORTH);
			{
				JLabel lblTitulo = new JLabel("Modalidad Eliminatoria");
				lblTitulo.setFont(new Font("Vani", Font.PLAIN, 20));
				panelTitulo.add(lblTitulo);
			}
		}
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
		{
			JPanel panelFormaPuntuacion = new JPanel();
			contentPanel.add(panelFormaPuntuacion);
			panelFormaPuntuacion.setMaximumSize(panel);
			{
				JLabel lblFormaDePuntuacin = new JLabel("Forma de Puntuaci\u00F3n:");
				panelFormaPuntuacion.add(lblFormaDePuntuacin);
				lblFormaDePuntuacin.setPreferredSize(label);
			}
			{
				cbForma = new JComboBox<String>();
				cbForma.setModel(new DefaultComboBoxModel<String>(new String[] {"Sets", "Puntos", "Final"}));
				panelFormaPuntuacion.add(cbForma);
				cbForma.setPreferredSize(datos);
			}
		}
		{
			JPanel panelCantidadSets = new JPanel();
			contentPanel.add(panelCantidadSets);
			panelCantidadSets.setMaximumSize(panel);
			{
				JLabel lblCantidadDeSets = new JLabel("Cantidad de Sets");
				panelCantidadSets.add(lblCantidadDeSets);
				lblCantidadDeSets.setPreferredSize(label);
			}
			{
				spCantidadSets = new JSpinner();
				spCantidadSets.setModel(new SpinnerNumberModel(1, 1, 9, 2));
				panelCantidadSets.add(spCantidadSets);
				spCantidadSets.setPreferredSize(datos);
			}
		}
		{
			JPanel panelTantosGanados = new JPanel();
			contentPanel.add(panelTantosGanados);
			panelTantosGanados.setMaximumSize(panel);
			{
				JLabel lblTantosGanadosPor = new JLabel("Tantos Ganados por Falta de Rival:");
				panelTantosGanados.add(lblTantosGanadosPor);
				lblTantosGanadosPor.setPreferredSize(label);
			}
			{
				txtFaltaRival = new JTextField();
				panelTantosGanados.add(txtFaltaRival);
				txtFaltaRival.setPreferredSize(datos);
				
			}
		}
		{
			Component glue = Box.createGlue();
			contentPanel.add(glue);
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.CENTER));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			buttonPane.setMaximumSize(panel);
			{
				okButton = new JButton("Aceptar");
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				okButton.addActionListener(new ActionListener() {
					
					public void actionPerformed(ActionEvent arg0) {
						if(camposObligatorios(getObligatorios())){
							setBoton(true);
							setSets((int) spCantidadSets.getValue());
							setForma(cbForma.getSelectedItem().toString());
							setRival(Integer.parseInt(txtFaltaRival.getText()));
							getParent().setFocusable(true);
							dispose();
						}
						else {
							gError.mostrarErrorCampos("Campos Obligatorios Faltantes");
						}
						
					}
				});

			}
			{
				Component horizontalStrut = Box.createHorizontalStrut(20);
				buttonPane.add(horizontalStrut);
			}
			{
				cancelButton = new JButton("Cancelar");
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						setBoton(false);
						getParent().setFocusable(true);
						dispose();
					}
				});
			}
		}
		getObligatorios().add(txtFaltaRival);
		getObligatorios().add(cbForma);
	}

	


	public String getForma() {
		return forma;
	}


	public void setForma(String forma) {
		this.forma = forma;
	}


	public int getSets() {
		return sets;
	}


	public void setSets(int sets) {
		this.sets = sets;
	}


	public int getRival() {
		return rival;
	}


	public void setRival(int rival) {
		this.rival = rival;
	}




}
